﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;

namespace QLKS.Views
{
    /// <summary>
    /// Interaction logic for ucDmTienTe.xaml
    /// </summary>
    public partial class ucDmTienTe : UserControl
    {
        //string columns = "matt,tygia,tentt";

        public ucDmTienTe()
        {
            InitializeComponent();
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            mainContent.StringBrowse = "matt:Mã:100:F;tygia:Tỷ giá:130;tentt:Tên tiền tệ:250";
            mainContent.TableSource = ViewModels.TienTeViewModel.GetDmTienTe();
            mainContent.F2 += new ucDmTemplate.GridKeyUp_F2(PressKey_F2);//Xem
            mainContent.F4 += new ucDmTemplate.GridKeyUp_F4(PressKey_F4);//Tạo mới
            mainContent.F3 += new ucDmTemplate.GridKeyUp_F3(PressKey_F3);//Chỉnh sửa
            mainContent.F7 += new ucDmTemplate.GridKeyUp_F7(PressKey_F7);//Copy
            mainContent.F6 += new ucDmTemplate.GridKeyUp_F6(PressKey_F6);//Refresh
            mainContent.F8 += new ucDmTemplate.GridKeyUp_F8(PressKey_F8);//Delete
        }

        void PressKey_F2(object sender, EventArgs e)
        {
            DataTable tb = mainContent.CurentRow;
            if (tb == null)
                return;
            frmKhaiBaoTienTe frm = new frmKhaiBaoTienTe(tb, Command.View);
            frm.Show();
        }

        void PressKey_F3(object sender, EventArgs e)
        {
            DataTable tb = mainContent.CurentRow;
            if (tb == null)
                return;
            frmKhaiBaoTienTe frm = new frmKhaiBaoTienTe(tb, Command.Edit);
            frm.ShowDialog();
            if (frm.UpdateSucces)
                mainContent.Update(ViewModels.TienTeViewModel.GetDmTienTe());
        }
        void PressKey_F8(object sender, EventArgs e)
        {
        }
        void PressKey_F4(object sender, EventArgs e)
        {
            frmKhaiBaoTienTe frm = new frmKhaiBaoTienTe(null,Command.New);
            frm.ShowDialog();
            if (frm.UpdateSucces)
                mainContent.Update(ViewModels.TienTeViewModel.GetDmTienTe());
        }
        void PressKey_F7(object sender, EventArgs e)
        {
            DataTable tb = mainContent.CurentRow;
            if (tb == null)
                return;
            frmKhaiBaoTienTe frm = new frmKhaiBaoTienTe(tb, Command.Copy);
            frm.ShowDialog();
            if (frm.UpdateSucces)
                mainContent.Update(ViewModels.TienTeViewModel.GetDmTienTe());
        }

        void PressKey_F6(object sender, EventArgs e)
        {
            mainContent.Update(ViewModels.TienTeViewModel.GetDmTienTe());
        }
    }
}
